home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_puffyclouds.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.7 KB  |  81 lines

  1. /* I took wave's lead and renamed starfield to KMPuffyclouds.sl -- tal@SpamSucks_cs.caltech.edu */
  2.  
  3. /*
  4.  * puffyclouds.sl -- RenderMan compatible surface shader for puffy
  5.  *                   clouds.
  6.  *
  7.  * DESCRIPTION:
  8.  *    Makes nice looking cumulous clouds like you would see in the sky
  9.  *    on a bright sunny day.  Works as a basic thresholded fBm.  Since
  10.  *    this texture is generally used as a backdrop, it does not take
  11.  *    lighting into account.  If you wanted a lit surface that looked like
  12.  *    puffy clouds (like painted clouds on a wall), then it would be pretty
  13.  *    easy to add the lighting.
  14.  *
  15.  * PARAMETERS:
  16.  *    txtscale - overall scaling factor
  17.  *    skycolor, cloudcolor - the obvious meanings
  18.  *    octaves, omega, lambda - control the fractal appearance of the clouds
  19.  *    threshold - fBm sum below this level is just blue sky
  20.  *
  21.  * ANTIALIASING:
  22.  *    None, but should be easy to add antialiasing simply by adaptively
  23.  *    setting the "octaves" parameter based on distance from eye point.
  24.  *
  25.  * AUTHOR:
  26.  *    C language version by F. Kenton Musgrave
  27.  *    Translation to RenderMan Shading Language by Larry Gritz.
  28.  *
  29.  * REFERENCES:
  30.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  31.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  32.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  33.  *
  34.  * HISTORY:
  35.  *    ??? - original C language version by Ken Musgrave
  36.  *    Apr 94 - translation to Shading Language by L. Gritz
  37.  *
  38.  * this file last updated 18 Apr 1994
  39.  */
  40.  
  41.  
  42.  
  43. /* Use signed Perlin noise */
  44. #define snoise(x) ((2*noise(x))-1)
  45.  
  46.  
  47. surface
  48. k3d_puffyclouds (float Ka = 0, Kd = 0;
  49.          float txtscale = 1;
  50.          color skycolor = color(.15, .15, .6);
  51.          color cloudcolor = color(1,1,1);
  52.          float octaves = 8, omega = 0.5, lambda = 2;
  53.          float threshold = 0;
  54.          )
  55. {
  56.   float value;
  57.   color Ct;      /* Color of the surface */
  58.   point PP;      /* Surface point in shader space */
  59.   float i, a, l, o;
  60.  
  61.   PP = txtscale * transform ("shader", P);
  62.  
  63.   /* Use fractional Brownian motion to compute a value for this point */
  64. /*  value = fBm (PP, omega, lambda, octaves); */
  65.   value = 0;
  66.   l = 1;  o = 1;  a = 0;
  67.   for (i = 0;  i < octaves;  i += 1) {
  68.       a += o * snoise (PP*l);
  69.       l *= 2;  o *= omega;
  70.     }
  71.   value = a;
  72.  
  73.   Ct = mix (skycolor, cloudcolor, smoothstep (threshold, 1, value));
  74.   
  75.   /* Shade like matte, but use color Ct */
  76.   Oi = 1;    /* Make it opaque */
  77.   Ci = Ct;   /* This makes the color disregard the lighting */
  78.   /* Uncomment the next line if you want the surface to actually be lit */
  79. /*  Ci = Ct * (Ka * ambient() + Kd * diffuse(faceforward(N,I))); */
  80. }
  81.